
package cl.migue.itunes;

import cl.migue.itunes.api.ITunesSearchAPI;
import cl.migue.itunes.data.ITunesProduct;
import cl.migue.itunes.data.ITunesProductList;
import flexjson.JSONDeserializer;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Miguel A. Fuentes Buchholtz
 * @email contacto AT migue DOT cl
 */
public class iTunes {

    private static JSONDeserializer<ITunesProductList> ipldeserializer = new JSONDeserializer<ITunesProductList>();

    public static ITunesProductList getProducts(List<String> keywords, int keywordsnumber, int top) {
        String iTunesJson = ITunesSearchAPI.searchItem(keywords, keywordsnumber, top);
        ITunesProductList il = ipldeserializer.deserialize(iTunesJson, ITunesProductList.class);
        if(il == null){
            il = new ITunesProductList();
        }
        if(il.results == null){
            il.results = new ArrayList<ITunesProduct>();
        }
        return il;
    }

    public static ITunesProductList getProducts(java.lang.String[] keywords, int keywordsnumber, int top) {
        String iTunesJson = ITunesSearchAPI.searchItem(keywords, keywordsnumber, top);
        ITunesProductList il = ipldeserializer.deserialize(iTunesJson, ITunesProductList.class);
        if(il == null){
            il = new ITunesProductList();
        }
        if(il.results == null){
            il.results = new ArrayList<ITunesProduct>();
        }
        return il;
    }
}
